package cn.pugle.selenium;

import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * 测试已生成的url能否访问
 * Created by tzp on 5/17/16.<br>
 */
public class TestUrl {
    public static void main(String[] args) throws IOException {
//        CloseableHttpClient httpClient = ClientUtils.createHttpClient(3, 3, 3);
        BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("/home/tzp/td2")));
        String line = null;
        int i =1;
        while ((line = br.readLine()) != null) {
            String[] split = line.split(",", -1);
            if (split.length == 1 || split[1].length() == 0) {
                System.out.println(split[0]);
            } else {
        CloseableHttpClient httpClient = HttpClients.createDefault();
                HttpGet httpGet = new HttpGet(split[1]);
                CloseableHttpResponse response = httpClient.execute(httpGet);
                if (response.getStatusLine().getStatusCode() == 400) {
                    System.out.println(split[0]);
                } else {
                    System.out.println(i+"ok");
                }
        httpClient.close();
            }
            i++;
        }
        br.close();
    }

    public static void main1(String[] args) throws IOException {
        CloseableHttpClient httpClient = HttpClients.createDefault();
        HttpGet httpGet = new HttpGet("https://lnk0.com/M9Y5w1");
        CloseableHttpResponse response = httpClient.execute(httpGet);
        System.out.println(response.getStatusLine().getStatusCode());
        if (response.getStatusLine().getStatusCode() == 400) {
            System.out.println("xx");
        } else {
//                    System.out.println(split[0]+"ok");
        }
        httpClient.close();
    }
}
